package com.nsgf.library.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.zhht.htzx.R;

/**
 * 项目名：    demo_sc
 * 包名：      com.njpl.myfishingspot.widget
 * 文件名：    CommomDialog
 * 创建者：    dc
 * 创建时间：  2024/10/15  11:07
 * 描述：      TODO
 */
public class BaseAlterDialog extends Dialog implements View.OnClickListener {
    private TextView contentTxt;
    private TextView submitTxt;
    private TextView cancleTxt;
    private TextView titleTxt;
    private View view_line;

    private Context mContext;
    private String content;
    private String alertTxt;
    private OnCloseListener listener;
    private OnSubmitListener submitlistener;
    private String positiveName;
    private String negativeName;
    private String title;

    public BaseAlterDialog(Context context) {
        super(context);
        this.mContext = context;
    }

    public BaseAlterDialog(Context context, int themeResId, String content) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
    }

    public BaseAlterDialog(Context context, int themeResId, String content, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
        this.listener = listener;
    }

    public BaseAlterDialog(Context context, int themeResId, String content, String buttonTitle, String title, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
        this.listener = listener;
        this.negativeName = buttonTitle;
        this.title = title;
    }
    public BaseAlterDialog(Context context, int themeResId, String content, String buttonTitle, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
        this.listener = listener;
        this.negativeName = buttonTitle;
    }


    public BaseAlterDialog(Context context, int themeResId, String content, OnSubmitListener submitlistener, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
        this.listener = listener;
        this.submitlistener = submitlistener;
    }

    public BaseAlterDialog(Context context, int themeResId, String content, String alertTxt, OnSubmitListener submitlistener, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
        this.alertTxt = alertTxt;
        this.listener = listener;
        this.submitlistener = submitlistener;
    }

    public BaseAlterDialog(Context context, int themeResId, String content, String positiveName, String negativeName, OnSubmitListener submitlistener, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
        this.positiveName = positiveName;
        this.negativeName = negativeName;
        this.listener = listener;
        this.submitlistener = submitlistener;
    }

    protected BaseAlterDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = context;
    }

    public BaseAlterDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    public BaseAlterDialog setPositiveButton(String name) {
        this.positiveName = name;
        return this;
    }

    public BaseAlterDialog setNegativeButton(String name) {
        this.negativeName = name;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_basealter);
        setCanceledOnTouchOutside(true);
        initView();
    }

    private void initView() {
        contentTxt = (TextView) findViewById(R.id.content);
        submitTxt = (TextView) findViewById(R.id.submit);
        cancleTxt = (TextView) findViewById(R.id.cancle);
        view_line = (View) findViewById(R.id.view_line);
        titleTxt = (TextView) findViewById(R.id.title);

        submitTxt.setOnClickListener(this);
        cancleTxt.setOnClickListener(this);

        contentTxt.setText(content);
        if (!TextUtils.isEmpty(positiveName)) {
            submitTxt.setText(positiveName);
        } else {
            submitTxt.setVisibility(View.GONE);
        }

        if (TextUtils.isEmpty(positiveName)||TextUtils.isEmpty(negativeName)){
            view_line.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(negativeName)) {
            cancleTxt.setText(negativeName);
        }
        if (!TextUtils.isEmpty(title)) {
            titleTxt.setText(title);
        }


    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.submit) {
            if (submitlistener != null) {
                submitlistener.onClick(this, true);
            }
        } else if (id == R.id.cancle) {
            if (listener != null) {
                listener.onCancleClick(this, true);
            }
        }
    }

    public interface OnCloseListener {
        void onCancleClick(Dialog dialog, boolean confirm);
    }

    public interface OnSubmitListener {
        void onClick(Dialog dialog, boolean confirm);
    }
}
